package com.kgc.scd.controller;

import com.kgc.scd.annotation.RequestShopUser;
import com.kgc.scd.annotation.TokenPermission;
import com.kgc.scd.bean.ShopHistory;
import com.kgc.scd.bean.ShopUser;
import com.kgc.scd.constant.CommonConstant;
import com.kgc.scd.service.ShopHistoryService;
import com.kgc.scd.util.PageSupport;
import com.kgc.scd.util.RedisUtils;
import com.kgc.scd.util.RequestResult;
import com.kgc.scd.vo.ShopGoodsVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created On : 2022/11/14 0014.
 * <p>
 * Author : shiguangchuan
 * <p>
 * Description: 历史足迹操作入口类
 */
@Slf4j
@RestController
@RequestMapping("/sgcServer")
public class ShopHistoryController {

    @Autowired
    private ShopHistoryService shopHistoryService;

    @Autowired
    private RedisUtils redisUtils;

    /**
     * @author : shiguangchuan
     * @date   : 2022/11/14 0014
     * @param  : []
     * @return : com.kgc.scd.util.RequestResult<java.lang.String>
     * @description : 添加历史足迹信息，存在数量限制及更新足迹信息
     */
    @PostMapping("/updateHistory")
    public void updateHistory(String goodsId,String userId){

        // 调用历史足迹业务，将足迹存入到redis中，并与数据库进行同步
        shopHistoryService.updateHistoryData(goodsId,userId);

    }


    /**
     * @author : shiguangchuan
     * @date   : 2022/11/15 0015
     * @param  : [userId]
     * @return : com.kgc.scd.util.RequestResult<?>
     * @description : 用户首次进入足迹页面商品的展示及条件查询的接口 
     */
    @GetMapping("/selectHistoryList")
    public PageSupport<ShopGoodsVO> selectHistoryList(@RequestParam(defaultValue = CommonConstant.DEFAULT_INIT_PAGE_NO) Integer pageNo,
                                                      @RequestParam(defaultValue = CommonConstant.DEFAULT_INIT_PAGE_SIZE) Integer pageSize,
                                                      @RequestParam String userId){

       return shopHistoryService.selectHistoryList(pageNo,pageSize,userId);

    }

    /**
     * @author : shiguangchuan
     * @date   : 2022/11/15 0015
     * @param  : [ids]
     * @return : boolean
     * @description : 用户删除历史足迹,通过历史足迹id
     */
    @PostMapping("/deleteHistory")
    public boolean deleteHistoryByIds(@RequestParam List<String> ids){

        // 调用批量删除足迹业务方法
        return shopHistoryService.deleteHistoryByIds(ids);

    }

    /**
     * @author : shiguangchuan
     * @date   : 2022/11/15 0015
     * @param  : [userId]
     * @return : boolean
     * @description : 用户删除全部历史足迹 
     */
    @PostMapping("/deleteAllHistory")
    public boolean deleteHistoryByUserId(@RequestParam String userId){

        // 调用全部删除足迹业务方法
        return shopHistoryService.deleteAllHistoryByUserId(userId);

    }

}
